package PTA_JAVA.JavaA.Javademo24;

import java.util.Scanner;
import java.util.ArrayList;
class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        ArrayListIntegerStack alis = new ArrayListIntegerStack();
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            System.out.println(alis.push(sc.nextInt()));
        }
        System.out.println(alis.peek()+","+alis.empty()+","+alis.size());
        System.out.println(alis);
        int x = sc.nextInt();
        for (int i = 0; i < x; i++) {
            System.out.println(alis.pop());
        }
        System.out.println(alis.peek()+","+alis.empty()+","+alis.size());
        System.out.println(alis);
    }
}
interface IntegerStack {
    public Integer push(Integer item); //如item为null，则不入栈直接返回null。否则直接入栈，然后返回item。
    public Integer pop();              //出栈，如栈为空，则返回null。
    public Integer peek();             //获得栈顶元素，如栈顶为空，则返回null。注意：不要出栈
    public boolean empty();           //如过栈为空返回true
    public int size();                //返回栈中元素数量
}
class ArrayListIntegerStack implements IntegerStack {
    ArrayList arr=new ArrayList();
    public ArrayListIntegerStack() {

    }

    @Override
    public Integer push(Integer item) {
        if(item==null){
            return null;
        }
        arr.add(item);
        return item;
    }

    @Override
    public Integer pop() {
        if(arr.size()==0){
            return null;
        }
        int a= (int) arr.get(arr.size()-1);
        arr.remove(arr.size()-1);
        return a;
    }

    @Override
    public Integer peek() {
        if(arr.isEmpty()){
            return null;
        }
        return (int)arr.get(arr.size()-1);
    }

    @Override
    public boolean empty() {
        return arr.isEmpty();
    }

    @Override
    public int size() {
        return arr.size();
    }

    @Override
    public String toString() {
        return arr.toString();
    }
}
